package com.wwg.util;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;

import java.util.List;
import java.util.stream.Collectors;

@Slf4j
public class BeanUtil {

    public static <T> List<T> copyList(List<? extends Object> resourceList, Class<T> targetClazz) {
        List<T> targetList = resourceList.stream().map(spmPullAverageExtraFeeExp -> {
            try {
                T t = targetClazz.newInstance();
                BeanUtils.copyProperties(spmPullAverageExtraFeeExp, t);
                return t;
            } catch (Exception e) {
                log.error(String.format("对象类型创建异常【%s】",targetClazz),e);
            }
            return null;
        }).collect(Collectors.toList());
        return targetList;
    }
}
